import { BaseWindow } from "../../../../component/window/BaseWindow";
import { IStallMyStallWindow } from "../interfaces/IStallMyStallWindow";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { BaseItem } from "../../common/BaseItem";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { ItemData } from "../../../resource/info/ItemData";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ParamsConst } from "../../../../common/global/ParamsConst";
import { ProxyType } from "../../../../common/global/ProxyType";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { IDragDrop } from "../../../../../com/mui/manager/IDragDrop";
import { ObjCreate } from "../../common/ObjCreate";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { SellItemCellRenderer } from "../cell/SellItemCellRenderer";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
type int = number;
//class MyStallWindow
    
    export  class MyStallWindow extends BaseWindow implements IStallMyStallWindow
    {
        constructor()
        {
            this._aryTab = [{"label": Language.getString(40817), "name":"item"}];
            super();
            titleHeight = 30;
            setSize(367, 416);
            title = Language.getString(40821);
            this.initView();
            this.addListeners();
            return;
        }

        /* internal  */hideAll(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallHideMyStallAll));
            return;
        }

        /* internal  */downItemHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._itemTileList.selectedIndex < 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40829));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallDownItem, this._itemTileList.dataProvider.getItemAt(this._itemTileList.selectedIndex)));
            return;
        }

        /* internal  */SellHandler(arg1: DragEvent): void
        {
            var loc1=arg1.dragItem as BaseItem;
            if (loc1.posType != EPlayerItemPosType._EPlayerItemPosTypeBag) 
            {
                return;
            }
            if (loc1 && loc1.itemData) 
            {
                this.showSellWindow(loc1.itemData);
            }
            return;
        }

        /* internal  */putInItemHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            if (loc1) 
            {
                this.showSellWindow(loc1);
            }
            return;
        }

        /* internal  */showSellWindow(arg1: ItemData): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallShowSellWindow, arg1));
            return;
        }

        public refreshItemList(arg1: Array<any>): void
        {
            if (arg1 && arg1.length > 0) 
            {
                this._itemTileList.dataProvider = new DataProvider(arg1);
            }
            else 
            {
                this._itemTileList.dataProvider = new DataProvider([null, null, null, null, null, null, null, null, null, null, null, null]);
            }
            return;
        }

        public refreshPetMountsList(): void
        {
            return;
        }

        public refreshBoothName(arg1: string): void
        {
            this._nameInput.text = arg1;
            return;
        }

        public set isInStall(arg1: Boolean)
        {
            this._isInStall = arg1;
            if (ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                this._btnCloseStall.label = this._isInStall ? MyStallWindow.CLOSESTALL : MyStallWindow.STARTSTALL;
            }
            return;
        }

        public blinkBoothMessage(arg1: Boolean): void
        {
            if (arg1) 
            {
                EffectManager.glowFilterReg(this._btnBoothMessage, [FilterConst.chatTipsFilter], 0.6, 10, 1);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this._btnBoothMessage);
            }
            return;
        }

        public /* override */ canDrop(arg1: IDragDrop, arg2: IDragDrop): Boolean
        {
            if (typeof arg1.dragSource === "itemdata") 
            {
                return true;
            }
            return false;
        }

        /* internal  */initView(): void
        {
            this.initBg();
            this.initTop();
            this.initMiddle();
            this.initBottom();
            return;
        }

        /* internal  */initBg(): void
        {
            ObjCreate.createBg(17, 41, 333, 306, this);
            return;
        }

        /* internal  */initTop(): void
        {
            var loc1=ObjCreate.createTextField(Language.getString(40822), 25, 47, 70, 28, this);
            this._nameInput = ObjCreate.createGTextInput(90, 46, 180, 20, this);
            this._nameInput.maxChars = 10;
            this._btnChangeName = ObjCreate.createGButton(Language.getString(40823), 273, 45, 70, 22, this);
            return;
        }

        /* internal  */initMiddle(): void
        {
            this._itemTileList = new GTileList();
            this._itemTileList.setSize(325, 244);
            this._itemTileList.rowHeight = 38;
            this._itemTileList.columnWidth = 158;
            this._itemTileList.horizontalGap = 5;
            this._itemTileList.verticalGap = 3;
            this._itemTileList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._itemTileList.setStyle("cellRenderer", SellItemCellRenderer);
            this._itemTileList.x = 22;
            this._itemTileList.y = 75;
            this._itemTileList.dataProvider = new DataProvider(new Array<any>(null, null, null, null, null, null, null, null, null, null, null, null));
            this.addChild(this._itemTileList);
            this._itemTileList.validateNow();
            return;
        }

        /* internal  */initBottom(): void
        {
            this._btnBoothMessage = ObjCreate.createGButton(Language.getString(40824), 25, 353, 70, 26, this);
            this._btnChangePrice = ObjCreate.createGButton(Language.getString(40825), 106, 353, 70, 26, this);
            this._btnChangePrice.enabled = false;
            this._btnDownItem = ObjCreate.createGButton(Language.getString(40826), 190, 353, 70, 26, this);
            if (ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                this._btnCloseStall = ObjCreate.createGButton(MyStallWindow.STARTSTALL, 274, 353, 70, 26, this);
            }
            this._tfTips = ObjCreate.createTextField(this.tips, 25, 384, 240, 20, this);
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnChangeName.addEventListener(flash.events.MouseEvent.CLICK, this.ChangeNameHandler);
            this._btnBoothMessage.addEventListener(flash.events.MouseEvent.CLICK, this.ShowOrHideBoothHandler);
            if (ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                this._btnCloseStall.addEventListener(flash.events.MouseEvent.CLICK, this.clickStallCloseHandler);
            }
            this._btnDownItem.addEventListener(flash.events.MouseEvent.CLICK, this.downItemHandler);
            addEventListener(DragEvent.Event_Move_In, this.SellHandler);
            Dispatcher.addEventListener(EventName.Stall_PutInItem, this.putInItemHandler);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            _closeBtn.configEventListener(flash.events.MouseEvent.CLICK, this.closeHandler, false, 9999);
            return;
        }

        /* internal  */ChangeNameHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._nameInput.text;
            if (loc1 == "") 
            {
                MsgManager.showRollTipsMsg(Language.getString(40827));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.StallChangeName, loc1));
            }
            return;
        }

        /* internal  */ShowOrHideBoothHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallShowOrHideMyBoothMsg));
            return;
        }

        /* internal  */closeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hideAll();
            return;
        }

        /* internal  */clickStallCloseHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            if (loc1.label != MyStallWindow.CLOSESTALL) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.StallRequestStart));
            }
            else 
            {
                this.endStall();
            }
            return;
        }

        public endStall(): void
        {
            if (this._isInStall) 
            {
                Alert.show(Language.getString(40828), null, Alert.OK | Alert.CANCEL, null, this.respondHandler);
            }
            else 
            {
                this.hideAll();
            }
            return;
        }

        /* internal  */respondHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                this.hideAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.StallEndStall));
            }
            return;
        }

        /* internal */ /* const */tips: string=Language.getString(40820);

        /* internal */ static /* const */CLOSESTALL: string=Language.getString(40818);

        /* internal */ static /* const */STARTSTALL: string=Language.getString(40819);

        /* internal */ /* var */_nameInput: GTextInput;

        /* internal */ /* var */_btnChangeName: GButton;

        /* internal */ /* var */_btnBoothMessage: GButton;

        /* internal */ /* var */_itemTileList: GTileList;

        /* internal */ /* var */_tfTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnChangePrice: GButton;

        /* internal */ /* var */_btnDownItem: GButton;

        /* internal */ /* var */_btnCloseStall: GButton;

        /* internal */ /* var */_aryTab: Array<any>;

        /* internal */ /* var */_isInStall: Boolean=false;
    }
